<template>
  <div id="cornerComment" v-if="dialogVisible">
    <div class="cornerComment-in">
      <div class="cornerComment-in-title">
        <span>新增合同</span>
        <span class="el-icon-circle-close close-Btn-line" @click="closePOpup"></span>
      </div>
      <div class="commentBody">
        <el-form ref="infoForm" label-width="140px">
          <el-form-item label="合同开始时间:" prop="name">
            <el-date-picker
                v-model="fromOption.start_time"
                type="date"
                value-format="yyyy-MM-dd"
                placeholder="选择日期">
            </el-date-picker>
          </el-form-item>
          <el-form-item label="合同结束时间:" prop="name">
            <el-date-picker
                v-model="fromOption.end_time"
                value-format="yyyy-MM-dd"
                type="date"
                placeholder="选择日期">
            </el-date-picker>
          </el-form-item>
          <el-form-item label="合同附件:" prop="name">
            <uploadFileModle number="20" @getFile="getFile" ref="uploadFileModle" :sycnStatus="true"
                             fileType="interaction_add"></uploadFileModle>
          </el-form-item>
        </el-form>
      </div>
      <div class="cornerComment-in-footer">
        <el-button @click.native="closePOpup" size="small">取消</el-button>
        <el-button @click="submitFromFn" size="small" type="primary">确定并保存
        </el-button>
      </div>
    </div>
  </div>
</template>

<script>
// recruitmentType first 在用查看招聘 ; history 历史查看招聘 ; examine 审核查看招聘
import { contractAdd} from '@/api/admin/contract'

export default {
  props: ['visible', 'id'], // recruitmentType examine 审核
  components: {},
  data() {
    return {
      dialogVisible: false,
      fromOption: {
        start_time: '',
        end_time: '',
      },
      fileList: ''
    }
  },
  watch: {
    visible() {
      this.dialogVisible = this.visible
      if (!this.visible) {
        this.fromOption = {
          start_time: '',
          end_time: '',
        }
        this.fileList = ''
      }
    }
  },
  created() {

  },
  methods: {
    getFile(option) {
      console.log('收到附件数据：', option)
      let a_ = this.getJson(option)
      let b_ = []
      for (let item of a_) {
        b_.push({
          name: item.name,
          src: item.src
        })
      }
      this.fileList = this.getJson(b_)
    },
    submitFromFn() {
      // 参数判断
      console.log('fromOption:', this.fromOption)
      console.log('fileList:', this.fileList)
      if (!this.fromOption.start_time) {
        this.$message.error('选择合同开始时间')
        return
      }
      if (!this.fromOption.end_time) {
        this.$message.error('选择合同结束时间')
        return
      }
      if (!this.fileList) {
        this.$message.error('上传合同附件')
        return
      }
      let data_ = {
        archives_id: this.id,
        start_time: this.fromOption.start_time,
        end_time: this.fromOption.end_time,
        file: JSON.stringify(this.fileList)
      }
      contractAdd(data_).then(res => {
        console.log('res:', res)
        if(!res.code){
          this.$message.success(res.msg)
          this.$emit('addInit')
          this.closePOpup()
        }else{
          this.$message.error(res.msg)
        }
      })
    },
    // 关闭弹窗
    closePOpup() {
      this.$emit('update:visible', false)
    },
    getJson(option) {
      return JSON.parse(JSON.stringify(option))
    }
  },
  mounted() {
  }
}
</script>
<style scoped>
#cornerComment {
  height: 100vh;
  width: 100%;
  position: fixed;
  top: 0;
  left: 0;
  background: rgba(0, 0, 0, .5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9;
}

.cornerComment-in {
  width: 50%;
  height: 40%;
  background: #fff;
  display: flex;
  flex-direction: column;
  border-radius: 5px;
}

.cornerComment-in-title {
  height: 50px;
  display: flex;
  align-items: center;
  border-bottom: 1px solid #ddd;
  font-size: 24px;
}

.cornerComment-in-title span {
  padding: 0 10px;
}

.cornerComment-in-title span:first-child {
  flex: 1;
  font-size: 16px;
}

.cornerComment-in-footer {
  height: 50px;
  border-top: 1px solid #ddd;
  display: flex;
  align-items: center;
  padding: 0 10px;
  justify-content: center;
}

.commentBody {
  padding: 10px 20px;
  flex: 1;
  overflow-y: auto;
}

.close-Btn-line {
  cursor: pointer;
}

.resruitment-title {
  padding: 5px 0;
  border-bottom: 2px solid #abd3f3;
  margin-bottom: 20px;
}

.el-radio {
  margin-right: 20px;
}

.jobTime {
  display: flex;
  align-items: center;
}

.jobTime span {
  padding: 0 10px;
}
</style>


